{extend name="Layout:edit" /}
{block name="content"}
<!-- form start -->
<form class="form-horizontal" action="{:U('promotionSave')}" method="post">
    <div class="box-body">
        <table class=".xsui-datatable table table-condensed table-bordered table-striped table-hover" data-comboboxurl="{:U('ProductPromption/getTreeJson')}">
            <thead>
            <th>名称</th>
            <th>促销活动</th>
            </thead>
            <tbody>
                {foreach name="list" item="vo"}
                <tr data-promotion="{$vo.promotion_ids}">
                    <td>{$vo.title}<input type="hidden" name="id[]" value="{$vo.id}" /></td>
                    <td>
                        {foreach name="promotions" item="vo2"}
                        <label class="checkbox-inline">
                            <input type="checkbox" name="promotion_ids_{$vo.id}[]" value="{$vo2.id}"> {$vo2.text}
                        </label>
                        {/foreach}
                    </td>
                </tr>
                {/foreach}
            </tbody>
        </table>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        <button type="button" class="btn btn-default xsui-btn-close-dialog">取消</button>
        <button type="submit" class="btn btn-primary pull-right">保存</button>
    </div>
    <!-- /.box-footer -->
</form>
{/block}
{block name="script_before"}
<script type="text/javascript">
    // 2017-3-23
    $('tbody tr').each(function () {
        var $tr = $(this);
        var promotion_ids = $tr.data('promotion')+'';
        if (undefined != promotion_ids && promotion_ids.length > 0) {
            var aids = promotion_ids.split(',');
            $tr.find(':checkbox').each(function () {
                var $chkbox = $(this);
                if (aids.indexOf($chkbox.val())>-1) {
                    $chkbox.prop('checked', true);
                }
            })
        }
    })
</script>
{/block}